package com.windowes.weichang.controller.manage;

import com.windowes.weichang.access.AccessLimit;
import com.windowes.weichang.common.ServerResponse;
import com.windowes.weichang.pojo.WUser;
import com.windowes.weichang.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/5/23 下午8:30
 * @description:
 *
 **/
@RestController
@Api(description = "人员管理相关API")
@RequestMapping("user")
public class UserController {


    @Autowired
    UserService userService;


    @ApiOperation(value = "添加/更新客户信息", notes = "【平台】")
    @PostMapping("addOrUpdate")
    public ServerResponse customers(@RequestBody WUser user) {
        return userService.addCustomer(user);
    }


    @ApiOperation(value = "获取客户列表", notes = "【平台】")
    @GetMapping("customers")
    public ServerResponse customers(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "15") int pageSize,
                                    String keyword

    ) {
        return userService.users(pageNo, pageSize, 1, keyword);
    }

    @ApiOperation(value = "获取员工列表", notes = "【平台】")
    @GetMapping("staffs")
    public ServerResponse staffs(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                 @RequestParam(value = "pageSize", defaultValue = "15") int pageSize,
                                 String keyword) {
        return userService.users(pageNo, pageSize, 0, keyword);
    }

    @ApiOperation(value = "根据关键字获取人员基本信息", notes = "不分页")
    @GetMapping("searchByKw")
    public ServerResponse searchByKw(String kw) {
        return userService.searchByKw(kw);
    }

    @ApiOperation(value = "根据id获取人员基本信息", notes = "")
    @GetMapping("user")
    public ServerResponse user(Integer id) {
        return userService.getUserById(id);
    }


    @ApiOperation(value = "更新密码", notes = "")
    @AccessLimit
    @PostMapping("updatePwd")
    public ServerResponse updatePwd(String oldPwd, String newPwd) {
        return userService.updatePwd(oldPwd, newPwd);
    }


    @ApiOperation(value = "获取个人信息", notes = "")
    @AccessLimit
    @GetMapping("userInfo")
    public ServerResponse getUserInfo() {
        return userService.getUserInfo();
    }


    @ApiOperation(value = "更新个人信息", notes = "")
    @AccessLimit
    @PostMapping("updateSelf")
    public ServerResponse updateSelf(@RequestBody WUser user) {
        return userService.updateSelf(user);
    }



    @ApiOperation(value = "获取客户列表", notes = "【商户】")
    @GetMapping("shop/customers")
    public ServerResponse shopCustomers(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "15") int pageSize,
                                    String keyword,Integer shopId

    ) {
        return userService.shopCustomers(pageNo, pageSize, shopId, keyword);
    }


    @GetMapping("customerInfo")
    @AccessLimit(shopUser = true)
    public ServerResponse  customerInfo(Integer demandId){
        return userService.customerInfo(demandId);
    }


}
